#include "BalanceMeter.h"
#include "PhotoBooth.h"

//--------------------------------------------------------------
void BalanceMeter::setup()
{
    ofBackground(0,0,0);
    ofSetFrameRate(70);
    industry = 0;
    culture = 396;
    left = true;
    stop = false;
    ofEnableSmoothing();
    OLDENGL.loadFont("OLDENGL.ttf", 15);
    OLDENGL2.loadFont("OLDENGL.ttf", 32);
    vgafix.loadFont("vgafix.ttf", 15);
    vgafix2.loadFont("vgafix.ttf", 32);
    balanceMeter.loadImage("BalanceMeter.png");
    balancePointer.loadImage("BalanceWijzer.png");
    balanceMeterVert.loadImage("BalanceMeterVert.png");
    balanceWijzerHead.loadImage("BalanceWijzerHead.png");
    balanceMeterG.loadImage("BalancetargetGreen.png");
    balanceMeterP.loadImage("BalancetargetPurple.png");
    balanceMeterO.loadImage("BalancetargetOrange.png");




    nyala.loadFont("Nyala.ttf", 15);
    nyala2.loadFont("Nyala.ttf", 32);
    nyala3.loadFont("Nyala.ttf", 40);

    screenWidth = ofGetScreenWidth();
    screenHeight = ofGetScreenHeight();

    topleft.x = (screenWidth / 2) - (culture / 2);
    topleft.y = (screenHeight / 2) - (160 / 2);

    topleft2.x = (screenWidth / 2) - (camWidth / 2);
    topleft2.y = (screenHeight / 2) - (camHeight / 2);

    startX = 0;
    startY = 220;
    stepY = 50;

    screenCenter = 512;
    screenRight = 1024;
}

//---------------------------------------a-----------------------
void BalanceMeter::update()
{
    if(stop == false)
    {
        if(industry == 395)
        {
            right = true;
            left = false;
        }
        if(industry == 0)
        {
            left = true;
            right = false;
        }
        if(left == true)
        {
            industry++;
            culture--;
        }
        if(right == true)
        {
            industry--;
            culture++;
        }
    }
}

//--------------------------------------------------------------

void BalanceMeter::draw()
{
    iPercentage = round((industry  / 396)*100);
    cPercentage = round((culture / 396)*100);

    balanceMeterVert.draw(screenRight - balanceMeterG.width*3,startY+stepY*0);

    ofSetColor(255,255,255);
    nyala2.drawString("Choose the balance",  startX+ balanceMeterG.width, startY + stepY * 3);
    nyala2.drawString("in culture and industry",  startX+ balanceMeterG.width, startY + stepY * 4);
    nyala2.drawString("you wish to play for",  startX+ balanceMeterG.width, startY + stepY * 5);


    if(currentPlayer == 1)
    {
        balanceMeterG.draw(screenRight - balanceMeterG.width*3 + 15, startY+stepY*0-10+industry);
        ofSetColor(84,255,0);
        char charArr3[255];
        sprintf(charArr3, "Player: %i", currentPlayer);
        drawTtfStringCentered(nyala2, charArr3, screenCenter,startY-stepY*0.7);

    }
    if(currentPlayer == 2)
    {
        balanceMeterP.draw(screenRight - balanceMeterP.width*3 + 15,startY+stepY*0-10+industry);
        ofSetColor(255,0,253);
        char charArr3[255];
        sprintf(charArr3, "Player: %i", currentPlayer);
        drawTtfStringCentered(nyala2, charArr3, screenCenter,startY-stepY*0.7);

    }
    if(currentPlayer == 3)
    {
        balanceMeterO.draw(screenRight - balanceMeterO.width*3 + 15, startY+stepY*0-10+industry);
        ofSetColor(255,152,8);
        char charArr3[255];
        sprintf(charArr3, "Player: %i", currentPlayer);
        drawTtfStringCentered(nyala2, charArr3, screenCenter,startY-stepY*0.7);


    }
    ofSetColor(255,255,255);
    char fpsStr[255];
    char fpsStr2[255];
    sprintf(fpsStr, "%i", cPercentage);
    sprintf(fpsStr2, "%i", iPercentage);
    ofSetColor(255,209,20);
    OLDENGL.drawString(fpsStr, screenRight - balanceMeterG.width*3 - 25, startY+stepY*0+10+industry);
    drawTtfStringCentered(nyala3,"Step  ", screenCenter - 40,startY-stepY*1.5);
    ofSetColor(124,185,255);
    vgafix.drawString(fpsStr2, screenRight - balanceMeterG.width*2 + 28, startY+stepY*0+10+industry);
    drawTtfStringCentered(nyala3,"1/3", screenCenter + 50,startY-stepY*1.5);

    ofSetColor(255,255,255);

    ofSetColor(124,185,255);
    drawTtfStringCentered(nyala2,"Press the button to decide", screenCenter,startY + stepY*10);
    ofSetColor(255,255,255);

}
/*
void BalanceMeter::draw2()
{

    iPercentage = round((industry  / 396)*100);
    cPercentage = round((culture / 396)*100);
    //iPercentage = industry;
    //cPercentage = culture;
    balanceMeter.draw(topleft.x, topleft.y);
    balancePointer.draw(topleft.x + industry,topleft.y+15);
    char fpsStr[255];
    char fpsStr2[255];
    sprintf(fpsStr, "%i", cPercentage);
    sprintf(fpsStr2, "%i", iPercentage);
    ofSetColor(255,209,20);
    OLDENGL.drawString(fpsStr, topleft.x+industry, topleft.y - 10);
    ofSetColor(124,185,255);
    vgafix.drawString(fpsStr2, topleft.x+industry, topleft.y + 175);
    ofSetColor(255,255,255);
    nyala.drawString("Step 2/3", topleft2.x+250,topleft2.y+camHeight+50);
    nyala2.drawString("Press button to set your goal", topleft.x - 30, topleft.y + 220);
}
*/

//--------------------------------------------------------------
void BalanceMeter::keyPressed(int key)
{
    if(key == 'a' || key == 'A')
    {
        stop = true;

    }
}


int BalanceMeter::getCultureValue()
{
    return culture;


}

int BalanceMeter::getIndustryValue()
{
    return industry;


}

int BalanceMeter::getiPercentage()
{
    return iPercentage;


}
int BalanceMeter::getcPercentage()
{
    return cPercentage;


}


bool BalanceMeter::isMeterSet()
{

    return stop;


}

void BalanceMeter::setPlayer(int player)
{

    currentPlayer = player;

}





